00001 /*! \file 00002 * X-Forge Util <br> 00003 * Copyright 2000-2003 Fathammer Ltd 00004 * 00005 * \brief Implementation of a "fast" random class. 00006 * 00007 * $Id: XFuFastRandom.h,v 1.7 2003/05/29 14:25:55 jetro Exp $ 00008 * $Date: 2003/05/29 14:25:55 $ 00009 * $Revision: 1.7 $ 00010 */ 00011 00012 #ifndef XFUFASTRANDOM_H_INCLUDED 00013 #define XFUFASTRANDOM_H_INCLUDED 00014 00015 00016 //! A "fast" pseudo random number generator class. 00017 /*! 00018 * Please note that the output from this pseudorandom number generator 00019 * is pretty poor, but it is suitable when all you need is just some noise. 00020 */ 00021 class XFuFastRandom 00022 { 00023 public: 00024 00025 //! Constructor. 00026 XFuFastRandom(); 00027 00028 //! Constructor with seed input. 00029 XFuFastRandom(UINT32 aSeed); 00030 00031 //! Returns the next random number. 00032 inline UINT32 next() 00033 { 00034 UINT32 v = mSeed1; 00035 mSeed1 = ((v >> 13) + (v << (32 - 13))); 00036 v = mSeed2 ^ 0x51549515; 00037 mSeed2 = mSeed1 ^ mSeed2; 00038 mSeed1 = v; 00039 return mSeed1; 00040 } 00041 00042 //! Re-seeds the random number generator. 00043 void seed(UINT32 aSeed); 00044 00045 protected: 00046 00047 UINT32 mSeed1; //!< Internal random number generator data. 00048 UINT32 mSeed2; //!< Internal random number generator data. 00049 }; 00050 00051 00052 #endif // !XFUFASTRANDOM_H_INCLUDED
![]() | ||||
![]() |
Confidential Copyright © 2002-2003 Fathammer | with doxygen by Dimitri van Heesch |